﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoreLib.MySQL.Mapping
{
    public class TypeTranslator
    {
        private static Dictionary<Type, string> toMySql = new Dictionary<Type, string>()
        {
            {typeof(sbyte), "tinyint"},
            {typeof(byte), "tinyint UNSIGNED"},
            {typeof(short), "smallint"},
            {typeof(ushort), "smallint UNSIGNED"},
            {typeof(int), "int"},
            {typeof(uint), "int UNSIGNED"},
            {typeof(long), "bigint"},
            {typeof(ulong), "bigint UNSIGNED"},
            {typeof(string), "varchar(200)"},
            {typeof(bool), "tinyint"},
            {typeof(DateTime), "datetime"},
            {typeof(byte[]), "varchar(200)"}
        };

        public static string TranslateToMySql(Type type)
        {
            if (toMySql.ContainsKey(type))
                return toMySql[type];
            throw new Exception("Not supported type " + type);
        }

        public static void AddOrUpdateTranslator(Type type, string value)
        {
            if (toMySql.ContainsKey(type))
                toMySql[type] = value;
            else
                toMySql.Add(type, value);
        }
    }
}